package me.joshua.tools4j.model.security;

import java.util.Collection;
import java.util.LinkedList;

import me.joshua.tools4j.model.User;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class Demo4jUserDetail implements UserDetails {

	private static final long serialVersionUID = 3442593435422974351L;

	public User user;

	public Demo4jUserDetail(User user) {
		this.user = user;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		LinkedList<GrantedAuthority> authorities = new LinkedList<GrantedAuthority>();
		authorities.add(new Demo4jGrantedAuthority("ROLE_USER"));
		return authorities;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUsername();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return user.getEnabled();
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
